package per.wsj.mmap

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import per.wsj.mmap.databinding.ActivityMainBinding
import android.os.Environment
import android.util.Log


class MainActivity : AppCompatActivity() {

    private val binding: ActivityMainBinding by lazy {
        ActivityMainBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        binding.btOpen.setOnClickListener {
            val path = externalCacheDir!!.absolutePath + "/mmaptest.txt"
            Log.e("MainActivity","path: $path")
            JniUtil.mmapOpen(path)
        }
        binding.btClose.setOnClickListener { v -> JniUtil.mmapClose() }
        binding.btWrite.setOnClickListener { v ->
            val content: String = binding.etContent.text.toString()
            JniUtil.mmapWrite(content)
            binding.etContent.setText("")
        }
    }

    /**
     * A native method that is implemented by the 'mmap' native library,
     * which is packaged with this application.
     */
    external fun stringFromJNI(): String

    companion object {
        // Used to load the 'mmap' library on application startup.
        init {
            System.loadLibrary("mmap")
        }
    }
}